Skip to content

feat(gax): implement inScope() in OpenTelemetryTracingTracer - #15033

Open
jinseopkim0 wants to merge 7 commits into
mainfrom
feat-otel-tracing-tracer-inscope
Open

jinseopkim0 wants to merge 7 commits into
mainfrom
feat-otel-tracing-tracer-inscope

Conversation

@jinseopkim0

Copy link
Copy Markdown
Contributor

Implements ApiTracer.inScope() in OpenTelemetryTracingTracer (with volatile operationSpan and attemptSpan fields) to activate the current attempt span on the calling thread's OpenTelemetry Context, falling back to the operation span when no attempt is in flight.

Because GrpcClientCalls.newCall already enters tracer.inScope(), this also links downstream grpc-java client spans to GAX's attempt span automatically.

b/499388983
b/570676007

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the inScope() method in OpenTelemetryTracingTracer to activate the current span (either the active attempt span or the overall operation span) on the calling thread's OpenTelemetry context. It also marks the operationSpan and attemptSpan fields as volatile to ensure thread safety. Additionally, comprehensive unit tests have been added to verify the correct behavior of inScope() and to ensure that there are no context leaks across threads. There are no review comments, and I have no feedback to provide.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces thread-safe span activation in OpenTelemetryTracingTracer by marking operationSpan and attemptSpan as volatile, implementing the inScope() method to manage OpenTelemetry scopes, and adding corresponding unit tests to verify scope fallback and multithreaded isolation. The reviewer suggests replacing the multiple volatile variables with an explicit lock (such as ReentrantLock) to guard the shared state, ensuring consistency and atomic updates across threads.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces thread safety to the OpenTelemetryTracingTracer class by using a ReentrantLock to synchronize access to operationSpan and attemptSpan. It also implements the inScope() method to activate the current span on the OpenTelemetry context, along with corresponding unit tests to verify behavior in single-threaded and multi-threaded scenarios. The review feedback recommends making the returned Scope in inScope() idempotent to prevent potential context leaks or corruption from multiple close() calls.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces thread-safety improvements to OpenTelemetryTracingTracer by utilizing a ReentrantLock to synchronize access to the operation and attempt spans. It also implements the inScope() method to manage the active OpenTelemetry context safely across threads, backed by new unit tests verifying scope activation, fallback behavior, and thread isolation. The review feedback recommends optimizing the inScope() implementation by replacing the AtomicBoolean with an anonymous class using a primitive boolean flag to avoid unnecessary object allocations on the critical path.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces thread-safe span management in OpenTelemetryTracingTracer by adding a ReentrantLock and helper methods to guard access to attemptSpan and operationSpan. It also implements the inScope() method to safely activate the current span and adds comprehensive unit tests to verify scope behavior, fallback logic, and multithreaded execution. The reviewer recommends ensuring that all other methods in the class accessing these spans are updated to use the new thread-safe helper methods to prevent potential data races.

@jinseopkim0

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces thread safety to OpenTelemetryTracingTracer by adding a ReentrantLock to guard access to operationSpan and attemptSpan. It also implements the inScope() method to activate the current span on the calling thread's OpenTelemetry context, and adds corresponding unit tests to verify scope activation, fallback behavior, and multithreaded execution safety. As there are no review comments, we have no additional feedback to provide.

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@jinseopkim0
jinseopkim0 marked this pull request as ready for review November 16, 2026 21:59
@jinseopkim0
jinseopkim0 requested a review from a team as a code owner November 16, 2026 21:59
@jinseopkim0
jinseopkim0 requested a review from blakeli0 November 16, 2026 21:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant